"use strict";
/* Controllers */
app.controller("schedulerAddController", ['$scope', '$location', '$rootScope', '$routeParams', 'schedulerAddService', function ($scope, $location, $rootScope, $routeParams, schedulerAddService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.p.id = $routeParams.id; // 如果id!=0为更新

    var errorFn = function (result) {
        alert(result);
    };

    $scope.addScheduler = function () {
        var vm = $scope.vm;
        var params = vm.p;
        var procFn = function (response) {
            if (response.success && response.data) {
                alert("执行成功！")
            } else {
                alert(response.msg);
            }
        };
        schedulerAddService.addScheduler(params, procFn, errorFn);
    };

    $scope.getScheduler = function () {
        var vm = $scope.vm;
        var params = {
            id: vm.p.id
        };
        var procFn = function (response) {
            if (response.success && response.data) {
                vm.p = (response.data);
            } else {
                alert(response.msg);
            }
        };
        schedulerAddService.getScheduler(params, procFn, errorFn);
    };

    if(vm.p.id!=0) {
        console.log(vm.p.id);
        $scope.getScheduler();
    }
}]);


/* Services */
app.service('schedulerAddService', ['ajaxService', function (ajaxService) {

    this.addScheduler = function (schedulers, successFunction, errorFunction) {
        ajaxService.AjaxPost(schedulers, "/star/api/onduty-app-service/v1/scheduler/addScheduler.do", successFunction, errorFunction);
    };

    this.getScheduler = function (schedulers, successFunction, errorFunction) {
        ajaxService.AjaxPost(schedulers, "/star/api/onduty-app-service/v1/scheduler/getScheduler.do", successFunction, errorFunction);
    };

}]);

